package com.xhs.listener;

import com.mongodb.client.model.changestream.ChangeStreamDocument;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.messaging.Message;
import org.springframework.data.mongodb.core.messaging.MessageListener;
import org.springframework.stereotype.Component;

/**
 * @desc:
 * @projectName: springboot-mongodb
 * @author: xhs
 * @date: 2023-11-16 016 21:56
 * @version: JDK 1.8
 */

@Slf4j
@Component

public class DocumentListener implements MessageListener<ChangeStreamDocument<Document>, Document> {

    @Override
    public void onMessage(Message<ChangeStreamDocument<Document>, Document> message) {
        log.info("Received Message in collection: {},", message.getProperties().getCollectionName());
        log.info("message raw: {}, ", message.getRaw());
        log.info("message body:{}", message.getBody());
    }
}
